/**
 * 
 */
package com.fwzc.giuseppe.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.fwzc.giuseppe.R;
import com.fwzc.giuseppe.adapter.MsgAdapter;
import com.fwzc.giuseppe.base.BaseActivity;

/**   
 *    
 * 类名称：MsgActivity 类描述： 创建人：何琳 创建时间：2015年8月13日 下午3:33:32
 * 
 * @version
 * 
 */
@SuppressLint("SimpleDateFormat") 
public class MsgActivity extends BaseActivity implements OnClickListener {

	private ListView listview;
	private MsgAdapter mAdapter;
	private ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>();
	private String news;
	private SimpleDateFormat format;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_msg);

		initBar();
		initView();
		initData();
	}

	private void initView() {
		listview = (ListView) findViewById(R.id.msg_listview);
		mAdapter = new MsgAdapter(this, dataList);
	}

	private void initData() {
		news = getIntent().getStringExtra("news");
		actionbar_side_name.setText("消息");
		iv_actionbar_side_left.setVisibility(View.VISIBLE);
//		HashMap<String, String> map = new HashMap<String, String>();
//		map.put("imageUrl", getResources().getDrawable(R.drawable.icon_circle_msg).toString());
//		map.put("title", "消息提醒");
//		map.put("time", "2015-8-12");
//		dataList.add(map);
//		map = new HashMap<String, String>();
//		map.put("imageUrl",
//				getResources().getDrawable(R.drawable.icon_circle_msg01).toString());
//		map.put("title", "第一次使用，请完善个人信息！");
//		map.put("time", "2015-8-12");
//		dataList.add(map);
		format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			JSONArray ja = new JSONArray(news);
			for (int i = 0; i < ja.length(); i++) {
				JSONObject jo = ja.getJSONObject(i);
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("imageUrl",jo.getString("messageImageURL"));
				map.put("title", jo.getString("messageContent"));
				map.put("time", format.format(new Date(jo.getInt("messageDate")*1000)));
				dataList.add(map);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		listview.setAdapter(mAdapter);
		iv_actionbar_side_left.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		if (v == iv_actionbar_side_left) {
			finish();
		}

	}

}
